<template>
  <div class="login-panel">
    <h2>用户登录</h2>

    <!-- tab切换 -->
    <el-tabs type="border-card" stretch  v-model="loginMethod">
      <el-tab-pane name="account">
        <template #label>
          <span>
            <el-icon><User /></el-icon>
            账号登录
          </span>
        </template>
        <login-account ref="accountFormRef"></login-account>
      </el-tab-pane>

      <el-tab-pane name="phone">
        <template #label>
          <span>
            <el-icon><Iphone /></el-icon>
            手机登录
          </span>
        </template>
        <login-phone ref="phtonFormRef"></login-phone>
      </el-tab-pane>
    </el-tabs>
    <div class="save-pass">
      <el-checkbox v-model="isSavePassword">记住密码</el-checkbox>
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button @click="toLogin" type="primary" class="login-button"
      >立即登录</el-button
    >
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from "vue"
import LoginAccount from "./login-account.vue"
import LoginPhone from "./login-phone.vue"
export default defineComponent({
  components: {
    LoginAccount,
    LoginPhone,
  },
  setup() {
    // 是否保存密码
    const isSavePassword = ref(true)
    // 账号登录面板
    const accountFormRef = ref<InstanceType<typeof LoginAccount>>()
    // 手机号登录面变
    const phtonFormRef = ref<InstanceType<typeof LoginPhone>>()
    // 绑定登录方式
    const loginMethod = ref('account')

    const toLogin = () => {
       // 账号登录
        if(loginMethod.value == "account") {
          accountFormRef.value?.actionLogin((isSavePassword.value))
        }else{
          // 手机号登录
          phtonFormRef.value?.actionLogin()
        }
    }

    return {
      isSavePassword,
      accountFormRef,
      toLogin,
      loginMethod,
      phtonFormRef,
    }
  },
})
</script>
<style lang="less" scoped>
.login-panel {
  width: 350px;
  margin-bottom: 130px;
  h2 {
    text-align: center;
  }
}
.el-form-item {
  width: 100%;
}
.el-tabs {
  height: 200px;
}
.save-pass {
  display: flex;
  justify-content: space-between;
  padding: 0 10px;
}
.login-button {
  width: 100%;
}
</style>
